import type { UploadUserFile } from "element-plus";

export interface GetSpuListParams {
  page: number;
  limit: number;
  category3Id: number;
}

/*
  {
    "records": [
      {
        "id": 9390,
        "spuName": "色蓝",
        "description": "45456661",
        "category3Id": 1,
        "tmId": 24405,
        "spuSaleAttrList": null,
        "spuImageList": null
      }
    ],
    "total": 2,
    "size": 1,
    "current": 1,
    "searchCount": true,
    "pages": 2
  }
*/
export interface SpuItem {
  id: number;
  spuName: string;
  description: string;
  // "category3Id": 1,
  tmId: number;
  // "spuSaleAttrList": null,
  // "spuImageList": null
}

export type SpuList = SpuItem[];

export interface GetSpuListResponse {
  records: SpuList;
  total: number;
  // "size": 1,
  // "current": 1,
  // "searchCount": true,
  // "pages": 2
}

export interface BaseSaleAttrItem {
  id: number;
  name: string;
}

export type BaseSaleAttrList = BaseSaleAttrItem[];

/*
  添加SPU
    {
      "spuName": "string",
      "tmId": 0
      "description": "string",
      "spuImageList": [
        {
          "imgName": "string",
          "imgUrl": "string",
        }
      ],
      "spuSaleAttrList": [
        {
          "baseSaleAttrId": 0,
          "saleAttrName": "string",
          "spuSaleAttrValueList": [
            {
              "baseSaleAttrId": 0,
              "saleAttrValueName": "string",
            }
          ]
        }
      ],
      "category3Id": 0,
    }
  修改SPU
    {
      "category3Id": 0,
      "description": "string",
      "id": 0,
      "spuImageList": [
        {
          "id": 0,
          "imgName": "string",
          "imgUrl": "string",
        }
      ],
      "spuName": "string",
      "spuSaleAttrList": [
        {
          "baseSaleAttrId": 0,
          "id": 0,
          "saleAttrName": "string",
          "spuSaleAttrValueList": [
            {
              "baseSaleAttrId": 0,
              "id": 0,
              "saleAttrValueName": "string",
            }
          ]
        }
      ],
      "tmId": 0
    }

  组件需要
    {
      "spuName": "string",
      "tmId": undefined | number
      "description": "string",
      "spuImageList": [ UploadUserFile[]
        {
          "name": "string",
          "url": "string",
        }
      ],
      "spuSaleAttrList": [
        {
          "baseSaleAttrId": 0,
          "saleAttrName": "string",
          "spuSaleAttrValueList": [
            {
              "baseSaleAttrId": 0,
              "saleAttrValueName": "string",
            }
          ]
        }
      ],
    }
*/
export interface SpuSaleAttrValueItem {
  id?: number;
  baseSaleAttrId: number;
  saleAttrValueName: string;
}

export type SpuSaleAttrValueList = SpuSaleAttrValueItem[];

export interface SpuSaleAttrItem {
  id?: number;
  baseSaleAttrId: number;
  saleAttrName: string;
  spuSaleAttrValueList: SpuSaleAttrValueList;
  isEdit?: boolean;
}

export type SpuSaleAttrList = SpuSaleAttrItem[];

export interface CommonSpu {
  id?: number;
  spuName: string;
  description: string;
  spuSaleAttrList: SpuSaleAttrList;
}

export interface SpuImageItem {
  id?: number;
  imgName: string;
  imgUrl: string;
}

export type SpuImageList = SpuImageItem[];

export interface SaveOrUpdateSpuParams extends CommonSpu {
  tmId: number;
  spuImageList: SpuImageList;
  category3Id: number;
}

export interface SpuFormData extends CommonSpu {
  tmId: undefined | number;
  spuImageList: UploadUserFile[];
}
